#pragma once
#include <iostream>
#include <deque>
#include "../house/base.hpp"
#include "../tools/base.hpp"
#include "../user/user.hpp"
#include "../utils/macro.hpp"

class Land{
private:
	HouseBase* house;
	ToolBase* tool;
	std::deque<std::pair<char, Color>> que;
public:
	Land(HouseBase* house):house(house),tool(nullptr){
		ASSERT(house!=nullptr);
	};
	~Land(){
		//TODO
		/* if (house!=nullptr) { */
		/* 	delete house; */
		/* } */
	}
	inline HouseBase* GetHouse(){return house;}
	inline ToolBase* GetTools(){return tool;}
	inline void SetTools(ToolBase* tool){
		this->tool=tool;
	}
	inline void DeleteTool(){
		delete tool;
		tool=NULL;
		return;
	} 
	inline void ChangeStatus(const User& user){
		que.push_back({user.MapChar(),user.MapColor()});
	}
	inline void ChangeStatus(HouseBase& house){
		que.push_back({house.MapChar(),house.MapColor()});
		this->house=&house;
	}
	inline void ChangeStatus(ToolBase& tool){
		que.push_back({tool.MapChar(),tool.MapColor()});
		this->tool=&tool;
	}
	inline char MapChar(){
		if (que.size()==0) {
			return house->MapChar();
		}
		auto now=que.back();
		return now.first;
	}
	inline Color MapColor(){
		if (que.size()==0) {
			return house->MapColor();
		}
		auto now=que.back();
		return now.second;
	}
	inline void Reset(){
		ASSERT(this->house!=NULL);
		if (que.size()>0) {
			que.pop_front();
		}
	}
};
